#include <iostream>
using namespace std;

int dp[31][300050] = {0}, price[31];
long long sum = 0;

int main() {
	int n, m, minus = 300050, result;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) { // sum是所有书的价格总和
		cin >> price[i];
		sum += price[i];
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= sum; j++) {
			dp[i][j] = j >= price[i] ? max(dp[i - 1][j], dp[i - 1][j - price[i]] + price[i]) : dp[i - 1][j]; // 01背包
			if (dp[i][j] >= m && dp[i][j] - m <= minus) { // 找到最接近的包邮价格
				result = dp[i][j];
				minus = dp[i][j] - m;
			}
		}
	}
	cout << result;
	return 0;
}